<template>
  <div class="calculator">
    <button @click="sub">-</button>
    <span v-text="num"></span>
    <button @click="add">+</button>
  </div>
</template>

<script>
export default {
  data() {
    return {
      num: 0,
    };
  },
  methods: {
    add() {
      if (this.num < 10) {
        this.num++;
      } else {
        alert("数值不能超过10");
      }
    },
    sub() {
      if (this.num > 0) {
        this.num--;
      } else {
        alert("数值不能小于0");
      }
    },
  },
};
</script>

<style scoped>
.calculator {
  width: 200px;
  margin: 20px auto;
}
button {
  padding: 5px 15px;
  margin: 0 10px;
  cursor: pointer;
}
</style>